package internationalenergytradingplatform.controller;

import internationalenergytradingplatform.dao.CommodityDao;
import internationalenergytradingplatform.pojo.Commodity;
import internationalenergytradingplatform.websocket.WebSocketServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/demo")
@CrossOrigin
public class Demo {
    @Autowired
    CommodityDao commodityDao;

    @Autowired
    private WebSocketServer webSocketServer;
    /**
     *
     * @author yjh
     * @date 2024/1/22 17:08
     开工纪念
     */
    @GetMapping
    public String startConstructionTest(){
        return "开工大吉";
    }
    /**
     *
     * @author yingfeng
     * @date 2024/2/13 18:17
     展示所有商品
     */
    @GetMapping("/commodity")
    public List<Commodity> getAllCommodity(){
        return commodityDao.getAllCommodity();
    }

    /**
     *
     * @author yingfeng
     * @date 2024/3/24 16:51
    测试websocket
     */
    @GetMapping("/websocket-test")
    public void websocketTest() {
        webSocketServer.sendToAllClient("这是来自服务端的消息：" + DateTimeFormatter.ofPattern("HH:mm:ss").format(LocalDateTime.now()));
    }
}
